/*
 * @Author: hucc
 * @Date: 2021-09-27 09:59:56
 * @LastEditors: hucc
 * @LastEditTime: 2021-10-05 19:48:52
 * @Description: 
 */
let arr1 = ['tom', 'vicky', 'jacky']
let keys = arr1.keys(); //Object [Array Iterator] {}
let values = arr1.values(); //Object [Array Iterator] {}
let entries = arr1.entries(); //Object [Array Iterator] {}
console.log(keys, values, entries);
//迭代器内部有一个指针,通过调用.next()方法往下移 
//用了几次.next()方法就会停留在指针下移的位置 下次用就从下移的位置开始而不是起点位置
//console.log(typeof values.next()); //object
// console.log(values.next()); //{ value: 'tom', done: false }
// console.log(values.next()); //{ value: 'vicky', done: false }
// console.log(values.next()); //{ value: 'jacky', done: false }
// console.log(values.next()); //{ value: undefined, done: true }

//while循环 拿到数组里面的values值
//重构迭代器中的 for of循环  
let item;
while (!(item = values.next()).done) {
    //!(item = values.next()).done等价于(item = values.next()).done == false
    console.log(item.value); //tom vicky jacky
}

//for of   常用来遍历迭代器对象
for (let entry of entries) {
    console.log(entry); //[ 0, 'tom' ] [ 1, 'vicky' ] [ 2, 'jacky' ]
}
// for (let value of values) {
//     console.log(value);
// }